<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja">
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>A canvas shadow text example</title>

<script src="../uuCanvas.js"></script>

<script>
function xcanvas() {
    drawShape(document.getElementById('slcanvas'));
    drawShape(document.getElementById('vmlcanvas'));
    drawShape(document.getElementById('flashcanvas'));
}
function matrix() {
    drawShape(document.getElementById('slcanvas'), 1);
    drawShape(document.getElementById('vmlcanvas'), 1);
    drawShape(document.getElementById('flashcanvas'), 1);
}

var globalAlpha = 1.0;
function switchAlpha() {
    globalAlpha -= 0.2;

    drawShape(document.getElementById('slcanvas'));
    drawShape(document.getElementById('vmlcanvas'));
    drawShape(document.getElementById('flashcanvas'));
}

var shadowBlur = 0;
function switchShadowBlur() {
    shadowBlur += 2;

    drawShape(document.getElementById('slcanvas'));
    drawShape(document.getElementById('vmlcanvas'));
    drawShape(document.getElementById('flashcanvas'));
}

function drawShape(canvas, matrix){
    if (!canvas.getContext){ return; }

    var ctx = canvas.getContext('2d');

    ctx.globalAlpha = globalAlpha;

    ctx.clear();
    if (matrix) {
        ctx.translate(-10, 5);
        ctx.scale(1.2, 0.8);
        ctx.rotate(5 * Math.PI / 180);
    }

    var lingrad = ctx.createLinearGradient(0,0,0,150);
    lingrad.addColorStop(0, '#00ABEB');
    lingrad.addColorStop(0.5, '#fff');
    lingrad.addColorStop(0.5, '#66CC00');
    lingrad.addColorStop(1, '#fff');

    ctx.textBaseline = "top";
    ctx.font = "36pt Arial";
    ctx.fillStyle = lingrad;
    ctx.strokeStyle = lingrad;
    ctx.xMissColor = "skyblue";

    var text = setShadow(ctx, "black", 10, 10, 4);
    ctx.fillText("fillText: "       + text, 20, 20);
    ctx.strokeText("strokeText: "   + text, 20, 80);
}
function setShadow(ctx, color, ox, oy, blur) {
    ctx.shadowColor = color;
    ctx.shadowOffsetX = ox;
    ctx.shadowOffsetY = oy;
    ctx.shadowBlur = blur + shadowBlur;
    return [color, ox, oy, blur].join(", ");
}
</script>
    <style type="text/css">
      body { margin: 20px; font-family: arial,verdana,helvetica; background: #fff;}
      h1 { font-size: 140%; font-weight:normal; color: #036; border-bottom: 1px solid #ccc; }
      canvas { border: 2px solid #000; float: left; margin-right: 20px; margin-bottom: 20px; }
      pre { float:left; display:block; background: rgb(238,238,238); border: 1px dashed #666; padding: 15px 20px; margin: 0 0 10px 0; }
    </style>
  </head>
  <body>
    <h1>A canvas <code style="text-shadow: 10px 10px 10px black">shadow text linearGradient</code> example</h1>
    <div>
      <input type="button" value="matrix effect" onclick="matrix()" />
      <input type="button" value="alpha -0.2" onclick="switchAlpha()" />
      <input type="button" value="shadowBlur +2" onclick="switchShadowBlur()" />
      <br />

      <canvas id="slcanvas" class="sl" width="620" height="150"></canvas>
      <canvas id="vmlcanvas" class="vml" width="620" height="150"></canvas>
      <canvas id="flashcanvas" class="flash" width="620" height="150"></canvas>
      <pre>
function xcanvas() {
    drawShape(document.getElementById('slcanvas'));
    drawShape(document.getElementById('vmlcanvas'));
    drawShape(document.getElementById('flashcanvas'));
}
function matrix() {
    drawShape(document.getElementById('slcanvas'), 1);
    drawShape(document.getElementById('vmlcanvas'), 1);
    drawShape(document.getElementById('flashcanvas'), 1);
}

var globalAlpha = 1.0;
function switchAlpha() {
    globalAlpha -= 0.2;

    drawShape(document.getElementById('slcanvas'));
    drawShape(document.getElementById('vmlcanvas'));
    drawShape(document.getElementById('flashcanvas'));
}

var shadowBlur = 0;
function switchShadowBlur() {
    shadowBlur += 2;

    drawShape(document.getElementById('slcanvas'));
    drawShape(document.getElementById('vmlcanvas'));
    drawShape(document.getElementById('flashcanvas'));
}

function drawShape(canvas, matrix){
    if (!canvas.getContext){ return; }

    var ctx = canvas.getContext('2d');

    ctx.globalAlpha = globalAlpha;

    ctx.clear();
    if (matrix) {
        ctx.translate(-10, 5);
        ctx.scale(1.2, 0.8);
        ctx.rotate(5 * Math.PI / 180);
    }

    var lingrad = ctx.createLinearGradient(0,0,0,150);
    lingrad.addColorStop(0, '#00ABEB');
    lingrad.addColorStop(0.5, '#fff');
    lingrad.addColorStop(0.5, '#66CC00');
    lingrad.addColorStop(1, '#fff');

    ctx.textBaseline = "top";
    ctx.font = "36pt Arial";
    ctx.fillStyle = lingrad;
    ctx.strokeStyle = lingrad;
    ctx.xMissColor = "skyblue";

    var text = setShadow(ctx, "black", 10, 10, 4);
    ctx.fillText("fillText: "       + text, 20, 20);
    ctx.strokeText("strokeText: "   + text, 20, 80);
}
function setShadow(ctx, color, ox, oy, blur) {
    ctx.shadowColor = color;
    ctx.shadowOffsetX = ox;
    ctx.shadowOffsetY = oy;
    ctx.shadowBlur = blur + shadowBlur;
    return [color, ox, oy, blur].join(", ");
}
      </pre>
    </div>
  </body>
</html>
